﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DCSLibrary;
using BDS;
using System.Data;
using Utils.DCSControl;
using Utils.DatabaseUtils;
using System.Configuration;
using DCTLib.Common;

public partial class _Default : dcPage
{
    protected string linkLogin = string.Empty;
    protected string linkRegister = string.Empty;  
    protected dcPage page;
    protected override void Load()
    {
        page = (dcPage)this.Page;
        if (!IsPostBack)
        {
            LoadMenu();
        }

        if (Session["User"] == null || string.IsNullOrEmpty(Session["User"].ToString()))
        {
            linkRegister = " <a href=\"/dang-ky-nguoi-dung.aspx\">Đăng ký</a> | ";           
            linkLogin = "<a href=\"/dang-nhap-nguoi-dung.aspx\">Đăng nhập</a> | ";            
        }
        else
        {
            linkLogin = "<a href=\"Members/quan-ly-tai-khoan.aspx\">Quản lý</a> | ";  
            linkLogin += "<a href=\"Default.aspx?user=logout\">[" + Session["User"].ToString() + "] LogOut</a> | ";
        }
        if (Request.QueryString["user"] == "logout")
        {
            Session.Remove("User");
            Session.Clear();
            CookieHelper.RemoveAllCookies();

            linkRegister = " <a href=\"/dang-ky-nguoi-dung.aspx\">Đăng ký</a> | ";
            linkLogin = "<a href=\"/dang-nhap-nguoi-dung.aspx\">Đăng nhập</a> | "; 
        }
    }
    
    protected override void Init()
    {        
    }

    protected void _btnLogout_Click(object sender, EventArgs e)
    {
        Utils.DC.Web.UI.PageUtility.SighOut(Session);
        //TODO xoa standard
        Response.Redirect("/");

    }
    private void LoadMenu()
    {
        try
        {
            rptMenu.DataSource = new CategoryPageUI().GetByParent(Convert.ToInt32(ConfigurationManager.AppSettings["NewsID"])).Tables[0];
            rptMenu.DataBind();
        }
        catch (Exception ex)
        {
        }
    }

    
}
